/*
    The I Ching (the Book of Changes) plasmoid.
    Copyright (C) 2002-2009 Jean Pierre Charalambos.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef HEXAGRAM_H
#define HEXAGRAM_H

#include "trigram.h"

/**
  *@author Jean Pierre Charalambos
  */

class Hexagram : public Datagram {
        Q_OBJECT

    public:
        Hexagram ( );
        Hexagram ( int );
        Hexagram ( Trigram *, Trigram * );
        Hexagram ( Line *, Line *, Line *, Line *, Line *, Line * );
        Hexagram ( QVector<int> );
        Hexagram ( int, int, int, int, int, int );
        virtual ~Hexagram() {
            delete inf;
            delete sup;
        }
        const Trigram * getSup()         const {
            return sup;
        }
        const Trigram * getInf() const {
            return inf;
        }
        const QVector<int> getIdVector() const {
            QVector<int> vec;
            for ( int i=0; i <3; i++ )
                vec.append ( inf->getComponent ( i )->getId() );
            for ( int i=0; i <3; i++ )
                vec.append ( sup->getComponent ( i )->getId() );
            return vec;
        }

    public slots:
        void setSup ( int i ) {
            sup->setId ( i );
        }
        void setSup ( Trigram * s ) {
            sup = s;
            setId();
        }
        void setInf ( int i ) {
            inf->setId ( i );
        }
        void setInf ( Trigram * i ) {
            inf = i;
            setId();
        }
        void setLine ( int i, int j ) {
            if ( i>=0 && i<3 )
                inf->setLine ( i,j );
            if ( i>2 && i<6 )
                sup->setLine ( ( i-3 ),j );
        }
        void setLineRandomly ( int i ) {
            if ( i>=0 && i<3 )
                inf->setLineRandomly ( i );
            if ( i>2 && i<6 )
                sup->setLineRandomly ( ( i-3 ) );
        }
        void setChangingLine ( int i )  {
            if ( i>=0 && i<3 )
                inf->setChangingLine ( i );
            if ( i>2 && i<6 )
                sup->setChangingLine ( ( i-3 ) );
        }
        void setFixedLine ( int i )  {
            if ( i>=0 && i<3 )
                inf->setFixedLine ( i );
            if ( i>2 && i<6 )
                sup->setFixedLine ( ( i-3 ) );
        }

    protected slots:
        //adjust hexagram id from components:
        virtual void generate();
        //adjust components from hexagram id:
        virtual void adjust ( int );

    protected:
        Trigram * inf;
        Trigram * sup;
};

#endif // HEXAGRAM_H
